/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.object;

import java.awt.Color;
import java.awt.Graphics;
import net.worlds.WorldsException;
import net.worlds.Main;
import org.jbox2d.common.Vec2D;
import org.jbox2d.dynamics.joints.RevoluteJointDef;


public class SimpleWeld extends Joint{
    public SimpleWeld() throws WorldsException
    {
        super("Weld");
        //x_;
    }
    @Override
    protected void createJoint() {
        jointDef = new RevoluteJointDef();
        jointDef.collideConnected = false;
        ((RevoluteJointDef)jointDef).initialize(part1.getBody(), part2.getBody(), anchor);
        ((RevoluteJointDef)jointDef).enableLimit = true;
        ((RevoluteJointDef)jointDef).lowerAngle = 0;
        ((RevoluteJointDef)jointDef).upperAngle = 0;
        joint = world.addJoint(jointDef);
    }
    @Override
    public void draw(Graphics g) throws WorldsException
    {
        if(!getBooleanProp("Visible") || part1 == null || part2 == null || joint == null)
            return;
        Vec2D screenPos = new Vec2D(joint.getAnchor1()).worldToScreen(Main.getView()); //!!!
        g.setColor(getColorProp("Color"));
        g.fillRect((int) screenPos.x - 5, (int) screenPos.y - 5, 10, 10);
        if(selected)
        {
            g.setColor(Color.white);
            g.drawRect((int) screenPos.x - 5, (int) screenPos.y - 5, 10, 10);
        }
    }
}
